var urlall = window.location.href;
var urlarr = urlall.split("?");
//获取URL参数并且
//对象处理Request['sem-5']和数组处理Request.['sem-5']方法不同

var token = '72bf621f08f1763a9997955a3f94fd10';
url1 = location.search;
var tag1, tag2, tag3, campaign, adgroup, ad, pageid, utm, tid, keywords, keywordid, matchtype, creative, adposition,
    pagenum, palcement, target, urlhead, urlfoot, sem1, sem2, sem3, sem4, clientfrom, followUserId;
var Request = {};
var sem5 = encodeURIComponent(urlarr[0]);
try {
    var urltest = (url1);

    //alert('正常')
    function GetRequest() {
        //var url = location.search; //获取url中"?"符后的字串
        var theRequest = new Object();
        if (urltest.indexOf("?") != -1) {
            var str = urltest.substr(1);
            strs = str.split("&");
            for (var i = 0; i < strs.length; i++) {
                theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
            }
        }
        return theRequest;
    }

    var Request = new Object();
    Request = GetRequest();


    if (typeof(Request.tag1) == 'undefined') {
        Request.tag1 = '';
    }
    if (typeof(Request.tag2) == 'undefined') {
        Request.tag2 = '';
    }
    if (typeof(Request.tag3) == 'undefined') {
        Request.tag3 = '';
    }
    if (typeof(Request.campaign) == 'undefined') {
        Request.campaign = '';
    }
    if (typeof(Request.adgroup) == 'undefined') {
        Request.adgroup = '';
    }
    if (typeof(Request.ad) == 'undefined') {
        Request.ad = '';
    }
    if (typeof(Request.pageid) == 'undefined') {
        Request.pageid = '';
    }
    if (typeof(Request.tid) == 'undefined') {
        Request.tid = '';
    }
    if (typeof(Request.utm) == 'undefined') {
        Request.utm = '';
    }
    if (typeof(Request.keywords) == 'undefined') {
        Request.keywords = '';
    }
    if (typeof(Request.keywordid) == 'undefined') {
        Request.keywordid = '';
    }
    if (typeof(Request.matchtype) == 'undefined') {
        Request.matchtype = '';
    }
    if (typeof(Request.creative) == 'undefined') {
        Request.creative = '';
    }
    if (typeof(Request.adposition) == 'undefined') {
        Request.adposition = '';
    }
    if (typeof(Request.pagenum) == 'undefined') {
        Request.pagenum = '';
    }
    if (typeof(Request.palcement) == 'undefined') {
        Request.palcement = '';
    }
    if (typeof(Request.target) == 'undefined') {
        Request.target = '';
    }
    if (typeof(Request.urlhead) == 'undefined') {
        Request.urlhead = '';
    }
    if (typeof(Request.urlfoot) == 'undefined') {
        Request.urlfoot = '';
    }
    if (typeof(Request['sem-1']) == 'undefined') {
        Request['sem-1'] = '';
    }
    if (typeof(Request['sem-2']) == 'undefined') {
        Request['sem-2'] = '';
    }
    if (typeof(Request['sem-3']) == 'undefined') {
        Request['sem-3'] = '';
    }
    if (typeof(Request['sem-4']) == 'undefined') {
        Request['sem-4'] = '';
    }
    if (typeof(Request['sem-5']) == 'undefined') {
        Request['sem-5'] = '';
    }
    if (typeof(Request.clientfrom) == 'undefined') {
        Request.clientfrom = '';
    }
    if (typeof(Request.followUserId) == 'undefined') {
        Request.followUserId = '';
    }

    tag1 = encodeURIComponent(Request.tag1);//81118581
    tag2 = encodeURIComponent(Request.tag2);//81118582
    tag3 = encodeURIComponent(Request.tag3);//81118583
    campaign = encodeURIComponent(Request.campaign);//81118584
    adgroup = encodeURIComponent(Request.adgroup);//81118585
    ad = encodeURIComponent(Request.ad);//81118586
    pageid = encodeURIComponent(Request.pageid);//81119673
    utm = encodeURIComponent(Request.utm);
    tid = encodeURIComponent(Request.tid);//81119671
    keywords = Request.keywords;
    keywordid = encodeURIComponent(Request.keywordid);
    matchtype = encodeURIComponent(Request.matchtype);
    creative = encodeURIComponent(Request.creative);
    adposition = encodeURIComponent(Request.adposition);
    pagenum = encodeURIComponent(Request.pagenum);
    palcement = encodeURIComponent(Request.palcement);
    target = encodeURIComponent(Request.target);
    urlhead = encodeURIComponent(Request.urlhead);
    urlfoot = encodeURIComponent(Request.urlfoot);
    sem1 = encodeURIComponent(Request['sem-1']);
    sem2 = encodeURIComponent(Request['sem-2']);
    sem3 = encodeURIComponent(Request['sem-3']);
    sem4 = Request['sem-4'];

    clientfrom = encodeURIComponent(Request.clientfrom);
    followUserId = encodeURIComponent(Request.followUserId);

    console.log(followUserId)
}
catch (err) {
    $.ajax({
        type: 'post',
        url: '',
        data: {'token': token, data: {"url": url1}}, //提交的数据
        dataType: 'json',
        success: function (Request) {
            //alert('发送成功')
            if (typeof(Request.tag1) == 'undefined') {
                Request.tag1 = '';
            }
            if (typeof(Request.tag2) == 'undefined') {
                Request.tag2 = '';
            }
            if (typeof(Request.tag3) == 'undefined') {
                Request.tag3 = '';
            }
            if (typeof(Request.campaign) == 'undefined') {
                Request.campaign = '';
            }
            if (typeof(Request.adgroup) == 'undefined') {
                Request.adgroup = '';
            }
            if (typeof(Request.ad) == 'undefined') {
                Request.ad = '';
            }
            if (typeof(Request.pageid) == 'undefined') {
                Request.pageid = '';
            }
            if (typeof(Request.tid) == 'undefined') {
                Request.tid = '';
            }
            if (typeof(Request.utm) == 'undefined') {
                Request.utm = '';
            }
            if (typeof(Request.keywords) == 'undefined') {
                Request.keywords = '';
            }
            if (typeof(Request.keywordid) == 'undefined') {
                Request.keywordid = '';
            }
            if (typeof(Request.matchtype) == 'undefined') {
                Request.matchtype = '';
            }
            if (typeof(Request.creative) == 'undefined') {
                Request.creative = '';
            }
            if (typeof(Request.adposition) == 'undefined') {
                Request.adposition = '';
            }
            if (typeof(Request.pagenum) == 'undefined') {
                Request.pagenum = '';
            }
            if (typeof(Request.palcement) == 'undefined') {
                Request.palcement = '';
            }
            if (typeof(Request.target) == 'undefined') {
                Request.target = '';
            }
            if (typeof(Request.urlhead) == 'undefined') {
                Request.urlhead = '';
            }
            if (typeof(Request.urlfoot) == 'undefined') {
                Request.urlfoot = '';
            }
            if (typeof(Request['sem-1']) == 'undefined') {
                Request['sem-1'] = '';
            }
            if (typeof(Request['sem-2']) == 'undefined') {
                Request['sem-2'] = '';
            }
            if (typeof(Request['sem-3']) == 'undefined') {
                Request['sem-3'] = '';
            }
            if (typeof(Request['sem-4']) == 'undefined') {
                Request['sem-4'] = '';
            }
            if (typeof(Request['sem-5']) == 'undefined') {
                Request['sem-5'] = '';
            }
            if (typeof(Request.clientfrom) == 'undefined') {
                Request.clientfrom = '';
            }
            if (typeof(Request.followUserId) == 'undefined') {
                Request.followUserId = '';
            }

            tag1 = encodeURIComponent(Request.tag1);//81118581
            tag2 = encodeURIComponent(Request.tag2);//81118582
            tag3 = encodeURIComponent(Request.tag3);//81118583
            campaign = encodeURIComponent(Request.campaign);//81118584
            adgroup = encodeURIComponent(Request.adgroup);//81118585
            ad = encodeURIComponent(Request.ad);//81118586
            pageid = encodeURIComponent(Request.pageid);//81119673
            utm = encodeURIComponent(Request.utm);
            tid = encodeURIComponent(Request.tid);//81119671
            keywords = Request.keywords;
            keywordid = encodeURIComponent(Request.keywordid);
            matchtype = encodeURIComponent(Request.matchtype);
            creative = encodeURIComponent(Request.creative);
            adposition = encodeURIComponent(Request.adposition);
            pagenum = encodeURIComponent(Request.pagenum);
            palcement = encodeURIComponent(Request.palcement);
            target = encodeURIComponent(Request.target);
            urlhead = encodeURIComponent(Request.urlhead);
            urlfoot = encodeURIComponent(Request.urlfoot);
            sem1 = encodeURIComponent(Request['sem-1']);
            sem2 = encodeURIComponent(Request['sem-2']);
            sem3 = encodeURIComponent(Request['sem-3']);
            sem4 = Request['sem-4'];

            clientfrom = encodeURIComponent(Request.clientfrom);
            followUserId = encodeURIComponent(Request.followUserId);
            Request = Request;

            console.log(Request)
            //console.log(tag1)
            //return Request;
        },
        error: function (Request) {
            alert('请求失败！');

            return false;
        },
    });
}
//console.log('正常： '+ Request['tag1']);
//var foot_input_name2,foot_input_phone2,foot_input_code2,foot_btn_dianji2,foot_btn_register2,foot_radio_sex2,regidea2,obj_input;
$(".soongetcode").click(function () {
    var foot_input_name2 = $(this).parents(".parentid").find('input.soonname').val();
    var foot_input_phone2 = $(this).parents(".parentid").find('input.soonphone');
    var foot_input_code2 = $(this).parents(".parentid").find('input.sooncode').val();
    var foot_btn_dianji2 = $(this).parents(".parentid").find('input.soongetcode');   //$(this)
    //var foot_btn_register2 =$(this).parents(".parentid").find('input.soonregsub');          //提交按钮
    var foot_radio_sex2 = $(this).parents(".parentid").find('.soonsex>label>input:checked').val();
    //console.log('foot_btn_dianji2:'+$(this).val());
    send_yzm($(this), $(this).val(), foot_input_phone2, foot_input_phone2.val());  //发送验证码
})

$(".soonregsub").click(function () {
    var foot_input_name2 = $(this).parents(".parentid").find('input.soonname');
    var foot_input_phone2 = $(this).parents(".parentid").find('input.soonphone');
    var foot_input_code2 = $(this).parents(".parentid").find('input.sooncode');
    //var foot_btn_dianji2 =$(this).parents(".parentid").find('input.soongetcode');     //获取验证码按钮
    var foot_btn_register2 = $(this).parents(".parentid").find('input.soonregsub');          //$(this)
    var foot_radio_sex2 = $(this).parents(".parentid").find('.soonsex>label>input:checked').val();
    var regidea2 = $(this).parents(".parentid").find('.soonidea');
    //console.log('foot_btn_dianji2:'+$(this).val());
    //alert(regidea2.val());
    register1021($(this), foot_input_name2, foot_radio_sex2, foot_input_phone2, foot_input_code2, regidea2); //注册手机号
})


//表单弹出  多系统兼容性处理
var u = navigator.userAgent;
var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; //android终端
var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
//alert('是否是Android：'+isAndroid);
//alert('是否是iOS：'+isiOS);
$('.Licurrent').text();
$(function () {
    $(".one_button").click(function () {
        var val = $(this).find("span.tanchutitle").text();
        var biaodan_button = $(this).find("span.button").text();
        var biaodan_zhuyi = $(this).find("span.zhuyi").text();
        var obj = $(this).attr("class");
        if ((obj.indexOf("banner")) != '-1') {
            var biaodan_zcidea = '<' + $('.Licurrent').text() + '>' + '用户申请查询' + '<' + $('.bannerInp').val() + '>' + '资质';//$(this).find("span.zcidea").text();
        } else {
            var biaodan_zcidea = $(this).find("span.zcidea").text();
        }
        $(".form_title").find("h2").text(val);
        $(".tanchutext").text(biaodan_zhuyi);
        $("#regidea5").val(biaodan_zcidea);
        //alert(biaodan_zcidea)
        $("#registerSubfoot0").val(biaodan_button);   //注意“registerSubfoot0”和“registerSubfoot5”可删除一个使用，依情况而定
        $("#registerSubfoot5").val(biaodan_button);
        $("#tanchuang #registerSubfoot2").val(biaodan_button);
        if (isiOS == true) {
            console.log('ios系统');
            document.getElementById("tanchuang").style.position = "absolute";
            $("#tanchuang").show();
            $("#tanchuang .side_form").fadeIn();
            document.body.style.position = "fixed";
        } else {
            console.log('其他系统');
            $("#tanchuang .side_form").css({'top': '50%', 'margin-top': '-185px'});
            $("#tanchuang").show();
            $("#tanchuang .side_form").fadeIn();
        }
    })

    $(".close").click(function () {
        $("#tanchuang").hide();
        $("#tanchuang .side_form").fadeOut();
        $("#regidea5").val('');
        $("#registerSubfoot5").val('');
        document.body.style.position = "relative";
    })
})


//encode  base64加密
//decode  base64解密
//=======以下是用户注册的函数代码，不能自主修改，如要修改请和bob协商=====================


//发送验证码函数
function send_yzm(btn_obj, btn_value, obj, obj_input) {
    //console.log(typeof($foot_input_phone2))
    //console.log(obj_input)
    var ret = is_mobile(obj_input);
    if (ret != 0) {
        //发送验证码倒计时并不可点击函数，btn_obj为按钮对象，countdown_time为设置按钮重复点击时间
        function xunhuan(btn_obj, btn_value, countdown_time) {
            if (typeof(yzmn) == "undefined") {
                yzmn = 6;  //yzmn为短信发送次数，这里为全局变量默认为6条
            }
            yzmn--;
            if (yzmn < 5) {
                alert('每个手机号单日发送短信的上限为5条，如果您长时间没有收到短信或输入验证码提交后显示错误，请联系在线客服！');
            }
            var val = btn_obj;

            var countdown = countdown_time;

            settime();

            function settime() {
                if (countdown == 0) {
                    val.removeAttr("disabled");
                    val.attr("style", 'color:black;');
                    val.val("点击获取");
                } else {
                    val.attr("disabled", "disabled");
                    val.attr("style", 'color:#A59C9C;');
                    btn_obj.val("获取(" + countdown + ")");
                    countdown--;
                    setTimeout(function () {
                        settime();
                    }, 1000);
                }
            }
        }

        xunhuan(btn_obj, btn_value, 20);	//调用120s不可重复点击发送验证码函数

        //获取验证码函数
        function sendyzm(phone1, smstp) {
            var phone = window.btoa(phone1);
            var url = "";
            var param = encodeURI("smsType=" + smstp + "&proxyid=32&mobile=" + phone);
            var allurl = location.href; //当前url
            //var token = '72bf621f08f1763a9997955a3f94fd10';
            var refer = document.referrer;//81119648  //上一级url
            Request.url = allurl;
            Request.refer = refer;
            // console.log('refer.substr: ' + refer.substr(0, 100));
            // console.log(Request)
            //console.log(phone)

            $.ajax({
                type: 'post',
                url: '/site/sendsms',
                data: {'token': token, mobile: phone}, //提交的数据
                dataType:'json',
                success: function (res) {
                    if (res.code == '') {
                        alert('短信发送成功！');
                    } else {
                        for (var i in res.data) {
                            layer.msg(res.data[i][0]);
                            break;
                        }
                        return false;
                    }

                },
                error: function (jqXHR) {
                    alert('请求失败！');
                    return false;
                },
            });

        };

        sendyzm(obj_input, '21', 'duanxin');
        obj.parents(".parentid").find('input.sooncode').focus();
        //obj_input.focus();
        //$("#footCode2").focus();
    } else {
        alert('请输入正确的手机号');
        obj.focus();
    }
}


//判断手机号是否为真实手机号，不合法返回0
function is_mobile(text) {
    /* var emp = /^\s*|\s*$/g;
    text = text.replace(emp,''); */
    var y = /^1[38][0123456789]\d{8}$/g;
    var y1 = /^14[56789]\d{8}$/g;
    var y2 = /^15[012356789]\d{8}$/g;
    var y3 = /^166\d{8}$/g;
    var y4 = /^17[012345678]\d{8}$/g;
    var y5 = /^19[89]\d{8}$/g;
    if (y.test(text)) {
        return 1;
    } else if (y1.test(text)) {
        return 2;
    } else if (y2.test(text)) {
        return 3;
    } else if (y3.test(text)) {
        return 4;
    } else if (y4.test(text)) {
        return 5;
    } else if (y5.test(text)) {
        return 6;
    } else {
        return 0;	//手机号不合法
    }
}


//手机注册传参函数
function register1021(obj_register, obj_name, obj_sex, obj_phone, obj_code, regidea) {
    var username = obj_name.val();
    //alert(username)
    var phone = obj_phone.val();
    var code = obj_code.val();
    if (username == null || username == "") {
        alert("姓名不能为空!");
        obj_name.focus();
        // $("#appellation").css('border','solid 1px red');
        return;
    }
    if (is_mobile(phone) == 0) {
        alert('您输入的手机号格式有误!');
        obj_phone.focus();
        return;
    }
    //var churl=$("#chaxunp").attr("data-url");
    var uname = $('.soonname').val();
    var usoso = $('#footCode0').val();
    var utel = $('.soonphone').val();
    var usex = $("input[name='sexFoot']:checked").val();
    var surl = document.referrer;
    var company = $('.bannerInp').val();

    $.post('/site/siginup', {
        nick_name: uname,
        sex: usex,
        mobile: utel,
        sms_code: usoso,
        beizhu: company,
        referer: surl
    }, function (data) {
        if (data.code == 1) {
            alert('提交查询成功!')
            zhuce_jin(obj_register, 20);
        } else {
            for (var i in data.data) {
                alert(data.data[i][0]);
                break;
            }
            return false;
        }

    }, 'json');


    //手机注册倒计时
    function zhuce_jin(btn_obj, countdown_time) {
        var val = btn_obj;
        //alert(btn_obj);
        var btn_value = btn_obj.val();
        var countdown = countdown_time;
        settime();

        function settime() {
            if (countdown == 0) {
                val.removeAttr("disabled");
                val.attr("style", 'color:black;');
                val.val(btn_value);
            } else {
                val.attr("disabled", "disabled");
                val.attr("style", 'color:#A59C9C;');
                val.val("提交中...(" + countdown + ")");
                countdown--;
                setTimeout(function () {
                    settime();
                }, 1000);
                if (countdown == 18) {
                    window.location.reload();
                }
            }
        }
    }

    //调用20s不可重复点击注册
    var f_name = username;
    var shouji = window.btoa(phone);   //实现字符串的Base64编码和解码，分别是window.btoa()函数和window.atob()解码函数。
    var code = code;

    //获取radio框里面的性别
    /* function get_sex(obj_sex){

         var sex;
         for(var i=0; i<obj_sex.length; i ++){
             if(obj_sex[i].checked){
                 sex = obj_sex[i].value;
             }
         }
         if (typeof(sex) == "undefined")
           {
               console.log('注册手机号时性别sex为空');
               return 1; //此时设置sex=1
         }
         return sex;
     }
     var f_gender = get_sex(obj_sex);*/

    //10.06加
    //获取用户基本信息
//	        var cip = returnCitySN['cip'];//81118589
//	        var cname = returnCitySN['cname'];

    //获取浏览器函数
    function get_browser() {
        var userAgent = navigator.userAgent; //取得浏览器的userAgent字符串
        var isOpera = userAgent.indexOf("Opera") > -1;
        if (isOpera) {
            return "Opera"
        }
        ; //判断是否Opera浏览器
        if (userAgent.indexOf("Firefox") > -1) {
            return "FF";
        } //判断是否Firefox浏览器
        if (userAgent.indexOf("Chrome") > -1) {
            return "Chrome";
        }
        if (userAgent.indexOf("Safari") > -1) {
            return "Safari";
        } //判断是否Safari浏览器
        if (userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1 && !isOpera) {
            return "IE";
        }
        ; //判断是否IE浏览器
    }

    var browser = get_browser();//81118588

    var scrWidth = screen.width;
    var scrHeight = screen.height;
    var fbl = scrWidth + '*' + scrHeight;//81118590


    //判断参数是否undefined  是则置空


    //赋值需要进行urlencoude加密
    var page_url = encodeURIComponent(escape(location.href)); //当前url
    var refer0 = document.referrer;
    refer0 = refer0.split('?');
    //alert('refer0:>>>>'+refer0[0]);
    var refer = encodeURIComponent(escape(refer0[0]));//81119648  //上一级url
    //alert(refer);


//console.log(keywords)		
    //alert(cip + '====' + cname + '====' + browser + '====' + fbl + '====' + url);  decode
    //获取get参数
    //$page_url = urlencode('http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
    //解决gb2312转码问题  只转keywords 关键词


    //var phone = foot_input_phone2.value;
    var userId = '';
    //var regidea1= $("#regidea2").val();
    //alert(regidea.value)
    //分配到ec
    var isFollower;
    var isFee;

}
	

	

		